package com.echo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.echo.activity.R;
import com.echo.model.Music;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by EchoGe on 2016/6/14.
 */
public class MusicAdapter extends RecyclerView.Adapter<MusicAdapter.ViewHolder>{

    private List<Music> mMusicList=new ArrayList<Music>();
    private Context mContext;

    public class ViewHolder extends RecyclerView.ViewHolder{

        public TextView name,singer;

        public ViewHolder(View itemView) {
            super(itemView);
            name= (TextView) itemView.findViewById(R.id.item_music_name);
            singer= (TextView) itemView.findViewById(R.id.item_music_singer);
        }
    }

    public MusicAdapter(){}

    public MusicAdapter(Context context){
        this.mContext=context;
    }

    public MusicAdapter(Context context,List<Music> musics){
        this.mContext=context;
        this.mMusicList=musics;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_music,parent,false);
        ViewHolder viewHolder=new ViewHolder(view);
        view.setTag(viewHolder);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.name.setText(mMusicList.get(position).getName());
        holder.singer.setText(mMusicList.get(position).getSinger());
    }

    @Override
    public int getItemCount() {
        return mMusicList.size();
    }

}
